import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMHW0OFL4lBdNFhLazwXBuQ6KzLFR2UH\n' +
  'uB9qmXSGKQiIp1fPj23URXlew2A3f7nIVmkHu30lFPK+YzhthRd7mU0CAwEAAQ=='

const privateKey = 'MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAwdbQ4UviUF00WEtr\n' +
  'PBcG5DorMsVHZQe4H2qZdIYpCIinV8+PbdRFeV7DYDd/uchWaQe7fSUU8r5jOG2F\n' +
  'F3uZTQIDAQABAkEAk3xoeFPtwan5LwlLcXAv3S1pOvsiBHwoGzdXxXJi/Erxoqyu\n' +
  'OD0DJJQpBMpvd26met3QXvTx7tcnKMohva9aAQIhAPI8PcZDFck/Igoxwz1OINcq\n' +
  'vpPcOMtoZOjWg440+hvNAiEAzNqQGjnWIT9O0oHOIFpXoUiFa4PMBtJlz0F6CIFQ\n' +
  '84ECIQDTyU2tUSv0FumZBicQK4XU+b9EIW/aj7xiQmMk6zadJQIgB04P7296jEr2\n' +
  'o5kPYaX3FABDCbd0chXUnZRnJqB944ECICAyZLEJZ0IgfGlhR3OpLxJvMFt47fpY\n' +
  '9gG8A/mdt9uR'

// 加密
export function encrypt (txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function decrypt (txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}
